﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DBUtility;//请先添加引用
namespace DBEmr.DAL
{
    /// <summary>
    /// 数据访问类MR_MEASURE_INDEX。
    /// </summary>
    public class MR_MEASURE_INDEX
    {
        DbHelperOra sql_help;
        public MR_MEASURE_INDEX()
        {
            sql_help = new DbHelperOra();
        }
        #region  成员方法


        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string FILE_NAME)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from MR_MEASURE_INDEX");
            strSql.Append(" where FILE_NAME='" + FILE_NAME + "' ");
            return sql_help.Exists(strSql.ToString());
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(DBEmr.Model.MR_MEASURE_INDEX model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into MR_MEASURE_INDEX(");
            strSql.Append("PATIENT_ID,VISIT_ID,FILE_NO,FILE_NAME,TOPIC,CREATOR_NAME,CREATOR_ID,CREATE_DATE_TIME,LAST_MODIFY_DATE_TIME,MR_CLASS,PRINT_FLAG,MR_CODE,FILE_FLAG,PARENT_NAME,PARENT_ID,PARENT_MODIFY_DATE_TIME,SUPPER_NAME,SUPPER_ID,SUPEER_MODIFY_DATE_TIME,HOUSEMAN,ON_DUTY_FLAG,CAPTION_DATE_TIME,FILE_EDIT_APPLY_PRIORITY,FILE_EDIT_APPLY_TIME_LIMIT,TEMPLET_ID,CONTENT");
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append("'" + model.PATIENT_ID + "',");
            strSql.Append("'" + model.VISIT_ID + "',");
            strSql.Append("'" + model.FILE_NO + "',");
            strSql.Append("'" + model.FILE_NAME + "',");
            strSql.Append("'" + model.TOPIC + "',");
            strSql.Append("'" + model.CREATOR_NAME + "',");
            strSql.Append("'" + model.CREATOR_ID + "',");
            strSql.Append("to_date('" + model.CREATE_DATE_TIME.ToString() + "','YYYY-MM-DD HH24:MI:SS'),");
            strSql.Append("to_date('" + model.LAST_MODIFY_DATE_TIME.ToString() + "','YYYY-MM-DD HH24:MI:SS'),");
            strSql.Append("'" + model.MR_CLASS + "',");
            strSql.Append("'" + model.PRINT_FLAG + "',");
            strSql.Append("'" + model.MR_CODE + "',");
            strSql.Append("'" + model.FILE_FLAG + "',");
            strSql.Append("'" + model.PARENT_NAME + "',");
            strSql.Append("'" + model.PARENT_ID + "',");
            strSql.Append("to_date('" + model.PARENT_MODIFY_DATE_TIME.ToString() + "','YYYY-MM-DD HH24:MI:SS'),");
            strSql.Append("'" + model.SUPPER_NAME + "',");
            strSql.Append("'" + model.SUPPER_ID + "',");
            strSql.Append("to_date('" + model.SUPEER_MODIFY_DATE_TIME.ToString() + "','YYYY-MM-DD HH24:MI:SS'),");
            strSql.Append("'" + model.HOUSEMAN + "',");
            strSql.Append("'" + model.ON_DUTY_FLAG + "',");
            strSql.Append("to_date('" + model.CAPTION_DATE_TIME.ToString() + "','YYYY-MM-DD HH24:MI:SS'),");
            strSql.Append("" + model.FILE_EDIT_APPLY_PRIORITY + ",");
            strSql.Append("to_date('" + model.FILE_EDIT_APPLY_TIME_LIMIT.ToString() + "','YYYY-MM-DD HH24:MI:SS'),");
            strSql.Append("'" + model.TEMPLET_ID + "',:content");
            strSql.Append(")");
            sql_help.ExecuteFile(strSql.ToString(), model.CONTENT);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(DBEmr.Model.MR_MEASURE_INDEX model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update MR_MEASURE_INDEX set ");
            strSql.Append("PATIENT_ID='" + model.PATIENT_ID + "',");
            strSql.Append("VISIT_ID='" + model.VISIT_ID + "',");
            strSql.Append("FILE_NO='" + model.FILE_NO + "',");
            strSql.Append("TOPIC='" + model.TOPIC + "',");
            strSql.Append("CREATOR_NAME='" + model.CREATOR_NAME + "',");
            strSql.Append("CREATOR_ID='" + model.CREATOR_ID + "',");
            strSql.Append("CREATE_DATE_TIME=" + "to_date('" + model.CREATE_DATE_TIME.ToString() + "','YYYY-MM-DD HH24:MI:SS'),");
            strSql.Append("LAST_MODIFY_DATE_TIME=" + "to_date('" + model.LAST_MODIFY_DATE_TIME.ToString() + "','YYYY-MM-DD HH24:MI:SS'),");
            strSql.Append("MR_CLASS='" + model.MR_CLASS + "',");
            strSql.Append("PRINT_FLAG='" + model.PRINT_FLAG + "',");
            strSql.Append("MR_CODE='" + model.MR_CODE + "',");
            strSql.Append("FILE_FLAG='" + model.FILE_FLAG + "',");
            strSql.Append("PARENT_NAME='" + model.PARENT_NAME + "',");
            strSql.Append("PARENT_ID='" + model.PARENT_ID + "',");
            strSql.Append("PARENT_MODIFY_DATE_TIME=" + "to_date('" + model.PARENT_MODIFY_DATE_TIME.ToString() + "','YYYY-MM-DD HH24:MI:SS'),");
            strSql.Append("SUPPER_NAME='" + model.SUPPER_NAME + "',");
            strSql.Append("SUPPER_ID='" + model.SUPPER_ID + "',");
            strSql.Append("SUPEER_MODIFY_DATE_TIME=" + "to_date('" + model.SUPEER_MODIFY_DATE_TIME.ToString() + "','YYYY-MM-DD HH24:MI:SS'),");
            strSql.Append("HOUSEMAN='" + model.HOUSEMAN + "',");
            strSql.Append("ON_DUTY_FLAG='" + model.ON_DUTY_FLAG + "',");
            strSql.Append("CAPTION_DATE_TIME=" + "to_date('" + model.CAPTION_DATE_TIME.ToString() + "','YYYY-MM-DD HH24:MI:SS'),");
            strSql.Append("FILE_EDIT_APPLY_PRIORITY=" + model.FILE_EDIT_APPLY_PRIORITY + ",");
            strSql.Append("FILE_EDIT_APPLY_TIME_LIMIT=" + "to_date('" + model.FILE_EDIT_APPLY_TIME_LIMIT.ToString() + "','YYYY-MM-DD HH24:MI:SS'),");
            strSql.Append("TEMPLET_ID='" + model.TEMPLET_ID + "',CONTENT=:content");
            //strSql.Append("CONTENT='" + model.CONTENT + "'");
            strSql.Append(" where FILE_NAME='" + model.FILE_NAME + "' ");
            sql_help.ExecuteFile(strSql.ToString(), model.CONTENT);
        }

        /// <summary>
        /// 更新一内容
        /// </summary>
        public void UpdateContent(DBEmr.Model.MR_MEASURE_INDEX model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update MR_MEASURE_INDEX set ");
            strSql.Append("CONTENT=:content");
            //strSql.Append("CONTENT='" + model.CONTENT + "'");
            strSql.Append(" where FILE_NAME='" + model.FILE_NAME + "' ");
            sql_help.ExecuteFile(strSql.ToString(), model.CONTENT);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(string FILE_NAME)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete MR_MEASURE_INDEX ");
            strSql.Append(" where FILE_NAME='" + FILE_NAME + "' ");
            sql_help.ExecuteSql(strSql.ToString());
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public DBEmr.Model.MR_MEASURE_INDEX GetModel(string FILE_NAME)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select PATIENT_ID,VISIT_ID,FILE_NO,FILE_NAME,TOPIC,CREATOR_NAME,CREATOR_ID,CREATE_DATE_TIME,LAST_MODIFY_DATE_TIME,MR_CLASS,PRINT_FLAG,MR_CODE,FILE_FLAG,PARENT_NAME,PARENT_ID,PARENT_MODIFY_DATE_TIME,SUPPER_NAME,SUPPER_ID,SUPEER_MODIFY_DATE_TIME,HOUSEMAN,ON_DUTY_FLAG,CAPTION_DATE_TIME,FILE_EDIT_APPLY_PRIORITY,FILE_EDIT_APPLY_TIME_LIMIT,TEMPLET_ID,CONTENT ");
            strSql.Append(" from MR_MEASURE_INDEX ");
            strSql.Append(" where FILE_NAME='" + FILE_NAME + "' ");
            DBEmr.Model.MR_MEASURE_INDEX model = new DBEmr.Model.MR_MEASURE_INDEX();
            DataSet ds = sql_help.Query(strSql.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.PATIENT_ID = ds.Tables[0].Rows[0]["PATIENT_ID"].ToString();
                model.VISIT_ID = ds.Tables[0].Rows[0]["VISIT_ID"].ToString();
                model.FILE_NO = ds.Tables[0].Rows[0]["FILE_NO"].ToString();
                model.FILE_NAME = ds.Tables[0].Rows[0]["FILE_NAME"].ToString();
                model.TOPIC = ds.Tables[0].Rows[0]["TOPIC"].ToString();
                model.CREATOR_NAME = ds.Tables[0].Rows[0]["CREATOR_NAME"].ToString();
                model.CREATOR_ID = ds.Tables[0].Rows[0]["CREATOR_ID"].ToString();
                if (ds.Tables[0].Rows[0]["CREATE_DATE_TIME"].ToString() != "")
                {
                    model.CREATE_DATE_TIME = DateTime.Parse(ds.Tables[0].Rows[0]["CREATE_DATE_TIME"].ToString());
                }
                if (ds.Tables[0].Rows[0]["LAST_MODIFY_DATE_TIME"].ToString() != "")
                {
                    model.LAST_MODIFY_DATE_TIME = DateTime.Parse(ds.Tables[0].Rows[0]["LAST_MODIFY_DATE_TIME"].ToString());
                }
                model.MR_CLASS = ds.Tables[0].Rows[0]["MR_CLASS"].ToString();
                model.PRINT_FLAG = ds.Tables[0].Rows[0]["PRINT_FLAG"].ToString();
                model.MR_CODE = ds.Tables[0].Rows[0]["MR_CODE"].ToString();
                model.FILE_FLAG = ds.Tables[0].Rows[0]["FILE_FLAG"].ToString();
                model.PARENT_NAME = ds.Tables[0].Rows[0]["PARENT_NAME"].ToString();
                model.PARENT_ID = ds.Tables[0].Rows[0]["PARENT_ID"].ToString();

                if (ds.Tables[0].Rows[0]["PARENT_MODIFY_DATE_TIME"].ToString() != "")
                {
                    model.PARENT_MODIFY_DATE_TIME = DateTime.Parse(ds.Tables[0].Rows[0]["PARENT_MODIFY_DATE_TIME"].ToString());
                }
                model.SUPPER_NAME = ds.Tables[0].Rows[0]["SUPPER_NAME"].ToString();
                model.SUPPER_ID = ds.Tables[0].Rows[0]["SUPPER_ID"].ToString();
                if (ds.Tables[0].Rows[0]["SUPEER_MODIFY_DATE_TIME"].ToString() != "")
                {
                    model.SUPEER_MODIFY_DATE_TIME = DateTime.Parse(ds.Tables[0].Rows[0]["SUPEER_MODIFY_DATE_TIME"].ToString());
                }
                model.HOUSEMAN = ds.Tables[0].Rows[0]["HOUSEMAN"].ToString();
                model.ON_DUTY_FLAG = ds.Tables[0].Rows[0]["ON_DUTY_FLAG"].ToString();
                if (ds.Tables[0].Rows[0]["CAPTION_DATE_TIME"].ToString() != "")
                {
                    model.CAPTION_DATE_TIME = DateTime.Parse(ds.Tables[0].Rows[0]["CAPTION_DATE_TIME"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FILE_EDIT_APPLY_PRIORITY"].ToString() != "")
                {
                    model.FILE_EDIT_APPLY_PRIORITY = int.Parse(ds.Tables[0].Rows[0]["FILE_EDIT_APPLY_PRIORITY"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FILE_EDIT_APPLY_TIME_LIMIT"].ToString() != "")
                {
                    model.FILE_EDIT_APPLY_TIME_LIMIT = DateTime.Parse(ds.Tables[0].Rows[0]["FILE_EDIT_APPLY_TIME_LIMIT"].ToString());
                }
                model.TEMPLET_ID = ds.Tables[0].Rows[0]["TEMPLET_ID"].ToString();
                if (ds.Tables[0].Rows[0]["CONTENT"].ToString().Equals(""))
                    return null;
                model.CONTENT = (byte[])(ds.Tables[0].Rows[0]["CONTENT"]);
                return model;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            //strSql.Append("select PATIENT_ID,VISIT_ID,FILE_NO,FILE_NAME,TOPIC,CREATOR_NAME,CREATOR_ID,CREATE_DATE_TIME,LAST_MODIFY_DATE_TIME,MR_CLASS,PRINT_FLAG,MR_CODE,FILE_FLAG,PARENT_NAME,PARENT_ID,PARENT_MODIFY_DATE_TIME,SUPPER_NAME,SUPPER_ID,SUPEER_MODIFY_DATE_TIME,HOUSEMAN,ON_DUTY_FLAG,CAPTION_DATE_TIME,FILE_EDIT_APPLY_PRIORITY,FILE_EDIT_APPLY_TIME_LIMIT,TEMPLET_ID");
            strSql.Append("select *");
            strSql.Append(" FROM MR_MEASURE_INDEX");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return sql_help.Query(strSql.ToString());
        }

        /*
        */

        #endregion  成员方法
    }
}

